package com.system.business.controller;

import cn.hutool.core.bean.BeanUtil;
import com.system.business.domain.Station;
import com.system.business.req.ConfirmOrderQueryReq;
import com.system.business.req.ConfirmOrderSaveReq;
import com.system.business.req.StationQueryReq;
import com.system.business.req.StationSaveReq;
import com.system.business.resp.ConfirmOrderQueryResp;
import com.system.business.resp.StationQueryResp;
import com.system.business.resp.TrainQueryResp;
import com.system.business.service.StationService;
import com.system.common.resp.CommonResp;
import com.system.common.resp.PageResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/station")
public class StationController {

    @Autowired
    private StationService stationService;
    @GetMapping("/query-list")
    public CommonResp<PageResp<StationQueryResp>> queryList(@Valid StationQueryReq req) {
        PageResp<StationQueryResp> list = stationService.queryList(req);
        return new CommonResp<>(list);
    }

    @PostMapping("/save")
    public CommonResp<Object> save(@Valid @RequestBody StationSaveReq req) {
        stationService.save(req);
        return new CommonResp<>();
    }

    @GetMapping("/query-all")
    public CommonResp<List<StationQueryResp>> queryList() {
        List<Station> stations = stationService.list();
        List<StationQueryResp> list = BeanUtil.copyToList(stations, StationQueryResp.class);
        return new CommonResp<>(list);
    }
}
